package cn.iocoder.yudao.framework.business.benefit.service;

import cn.iocoder.yudao.framework.business.basic.dao.query.CoreQueryWrapper;
import cn.iocoder.yudao.framework.business.basic.service.CrudService;
import cn.iocoder.yudao.framework.business.basic.service.impl.BaseService;
import cn.iocoder.yudao.framework.business.benefit.pojo.dto.BenefitQueryDTO;
import cn.iocoder.yudao.framework.business.benefit.pojo.dto.BenefitSaveDTO;
import cn.iocoder.yudao.framework.business.benefit.pojo.po.BenefitEntity;
import cn.iocoder.yudao.framework.business.benefit.pojo.vo.BenefitVO;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import jakarta.annotation.Nonnull;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

/**
 * 权益保障 Service 实现类
 *
 * @author 山野羡民
 */
@Service
@Validated
public abstract class BenefitBaseService<DO extends BenefitEntity> extends BaseService<DO, BenefitVO, BenefitQueryDTO> implements BenefitService<DO>, CrudService<DO, BenefitVO, BenefitSaveDTO, BenefitQueryDTO> {

    @Nonnull
    @Override
    protected CoreQueryWrapper<DO> buildQueryWrapper(BenefitQueryDTO param) {
        CoreQueryWrapper<DO> wrapper = super.buildQueryWrapper(param);
        wrapper.eqIfPresent("category_id", param.getCategoryId());
        wrapper.orderByDesc("category_id");
        wrapper.orderByAsc("sort");
        wrapper.orderByDesc("id");
        return wrapper;
    }

    @Override
    public DO convertToEntity(BenefitSaveDTO param) {
        return BeanUtils.toBean(param, resolveEntityClass());
    }

}
